#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define MAX_EXPRESSION_LENGTH 100

typedef struct Node {
    char value[MAX_EXPRESSION_LENGTH];
    struct Node* left;
    struct Node* right;
} Node;

Node* create_node(char* value) {
    Node* node = (Node*)malloc(sizeof(Node));
    strcpy(node->value, value);
    node->left = NULL;
    node->right = NULL;
    return node;
}

Node* build_expression_tree(char** expression) {
    char* token = *expression;
    *expression = token + strlen(token) + 1;
    Node* node = create_node(token);
    if (isdigit(token[0])) {
        return node;
    }
    node->left = build_expression_tree(expression);
    node->right = build_expression_tree(expression);
    return node;
}

void inorder_traversal(Node* node) {
    if (node == NULL) {
        return;
    }
    if (!isdigit(node->value[0]) && node->left != NULL) {
        printf("(");
    }
    inorder_traversal(node->left);
    printf("%s ", node->value);
    inorder_traversal(node->right);
    if (!isdigit(node->value[0]) && node->right != NULL) {
        printf(")");
    }
}

void free_tree(Node* node) {
    if (node == NULL) {
        return;
    }
    free_tree(node->left);
    free_tree(node->right);
    free(node);
}

int main() {
    char expression[MAX_EXPRESSION_LENGTH];
    fgets(expression, MAX_EXPRESSION_LENGTH, stdin);
    char* tokens[MAX_EXPRESSION_LENGTH];
    int num_tokens = 0;
    char* token = strtok(expression, " ");
    while (token != NULL) {
        tokens[num_tokens++] = token;
        token = strtok(NULL, " ");
    }
    Node* root = build_expression_tree(tokens);
    inorder_traversal(root);
    printf("\n");
    free_tree(root);
    return 0;
}